package com.night.icm.persistence.base.repository;

import com.night.icm.persistence.base.entity.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * TeacherRepository
 *
 * @author Liao ZhiYong
 * @date 2020/2/13
 */
@Repository
public interface TeacherRepository extends JpaRepository<Teacher, Long>, JpaSpecificationExecutor<Teacher> {

    /**
     * 通过code查找教师
     *
     * @param code 教师code
     * @return 教师信息
     */
    Teacher findByCode(String code);

    /**
     * 通过用户id查找教师
     *
     * @param userId 用户id
     * @return 教师
     */
    @Query("from Teacher as t where t.user.id = :userId")
    Teacher findByUserId(@Param("userId") Integer userId);
}
